package com.cyms.modules.card.controller;

import java.util.Arrays;
import java.util.Map;

import com.cyms.common.annotation.SysLog;
import com.cyms.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cyms.modules.card.entity.FuelcardEntity;
import com.cyms.modules.card.service.FuelcardService;
import com.cyms.common.utils.PageUtils;
import com.cyms.common.utils.R;



/**
 * 加油卡信息
 *
 * @author low
 * @email tolower@foxmail.com
 * @date 2018-12-08 14:54:32
 */
@RestController
@RequestMapping("card/fuelcard")
public class FuelcardController extends AbstractController {
    @Autowired
    private FuelcardService fuelcardService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("card:fuelcard:list")
    public R list(@RequestParam Map<String, Object> params){
        params.put("createOrg",getUser().getCompanyId());
        PageUtils page = fuelcardService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("card:fuelcard:info")
    public R info(@PathVariable("id") Long id){
			FuelcardEntity fuelcard = fuelcardService.selectById(id);

        return R.ok().put("fuelcard", fuelcard);
    }

    /**
     * 保存
     */
    @SysLog("新增加油卡信息")
    @RequestMapping("/save")
    @RequiresPermissions("card:fuelcard:save")
    public R save(@RequestBody FuelcardEntity fuelcard){
    	fuelcard.setStatus("1");
			fuelcardService.insert(fuelcard);

        return R.ok();
    }

    /**
     * 修改
     */
    @SysLog("修改加油卡信息")
    @RequestMapping("/update")
    @RequiresPermissions("card:fuelcard:update")
    public R update(@RequestBody FuelcardEntity fuelcard){
			fuelcardService.updateById(fuelcard);

        return R.ok();
    }

    /**
     * 删除
     */
    @SysLog("删除加油卡信息")
    @RequestMapping("/delete")
    @RequiresPermissions("card:fuelcard:delete")
    public R delete(@RequestBody Long[] ids){
			fuelcardService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
